package com.tth.learn.addproperties;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @Author tth
 * @Date 2022/12/14 16:37
 */
public class CollectionsTest {
    @Test
    public void test1() {
        List list = new ArrayList();
        list.add(11);
        list.add(989);
        list.add(454);
        list.add(89);
        list.add(23);

        // 错误写法，会报java.lang.IndexOutOfBoundsException: Source does not fit in dest 异常
//        List dest = new ArrayList();
//        Collections.copy(dest, list);

        // 正确写法
        List dest = Arrays.asList(new Object[list.size()]);
        Collections.copy(dest, list);
        System.out.println(dest);
    }
}
